<?php

namespace app\admin\validate;
use think\Validate;
use Workerman\Crontab\Parser;
class CrontabV extends Validate
{
    protected $rule = [
        'name|任务名称'  =>  'require|max:25',
        'rule|定时规则' =>  'require|CheckCrontabValid',
        'type|任务类型' =>  'require',
        'command|执行命令' =>  'require',
        'time_out|执行超时时间' =>  'require|integer',
        'status|执行状态' =>  'require',
    ];
    protected $scene = [
        'add'   => ['name', 'rule', 'type', 'command','time_out','status'],
    ];
	protected  function  CheckCrontabValid($v){
		//判断 crontab 规则是否有效
        $isok = (new Parser())->isValid($v);

        if(!$isok){
            return '定时规则错误';
        }
        return  true;
	}
}